package com.ruoyi.ratedemo.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.ratedemo.domain.Friend;
import com.ruoyi.ratedemo.mapper.FriendMapper;
import com.ruoyi.ratedemo.service.FriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FriendServiceImpl implements FriendService {
    @Autowired
    private FriendMapper friendMapper;

    @Override
    public List getFriendsByUserId(int userId) {
        return friendMapper.getFriendsByUserId(userId);
    }

    @Override
    public void addFriend(Integer userId, Integer friendId) {
        // 检查是否已经是好友
        int count = friendMapper.countFriends(userId,friendId);
        if (count > 0) {
           throw new RuntimeException("已经是好友");
        }

        // 添加好友
        friendMapper.addFriend(userId, friendId);
        friendMapper.addFriend(friendId, userId);
    }

    @Override
    public void deleteFriend(Integer userId, Integer friendId) {
        friendMapper.deleteFriend(userId, friendId);
    }
}
